<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseWards.class.php';

Class Wards {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjWards = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWards = new BaseWards();
			$objWards->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWards->setRoomNumber( ( true == isset( $row["room_number"] ) ) ? $row["room_number"] : 'NULL' );
			$objWards->setWardTypeId( ( true == isset( $row["ward_type_id"] ) ) ? $row["ward_type_id"] : 'NULL' );
			$objWards->setRate( ( true == isset( $row["rate"] ) ) ? $row["rate"] : 'NULL' );
			$objWards->setIsAvaliable( ( true == isset( $row["is_avaliable"] ) ) ? $row["is_avaliable"] : 'NULL' );
			$objWards->setMoveOutDate( ( true == isset( $row["move_out_date"] ) ) ? $row["move_out_date"] : 'NULL' );
			$objWards->setReservationId( ( true == isset( $row["reservation_id"] ) ) ? $row["reservation_id"] : 'NULL' );
			$objWards->setReportingDoctorId( ( true == isset( $row["reporting_doctor_id"] ) ) ? $row["reporting_doctor_id"] : 'NULL' );
			$objWards->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objWards->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objWards->setFacilities( ( true == isset( $row["facilities"] ) ) ? $row["facilities"] : 'NULL' );
			$objWards->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objWards->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objWards->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objWards->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjWards, $objWards );
		}
		return $arrobjWards;
	}
	public function fetchAllWards() {
		$result = $this->connection->RunQuery("SELECT * FROM WARDS");
		$arrobjWards = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWards = new BaseWards();
			$objWards->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWards->setRoomNumber( ( true == isset( $row["room_number"] ) ) ? $row["room_number"] : 'NULL' );
			$objWards->setWardTypeId( ( true == isset( $row["ward_type_id"] ) ) ? $row["ward_type_id"] : 'NULL' );
			$objWards->setRate( ( true == isset( $row["rate"] ) ) ? $row["rate"] : 'NULL' );
			$objWards->setIsAvaliable( ( true == isset( $row["is_avaliable"] ) ) ? $row["is_avaliable"] : 'NULL' );
			$objWards->setMoveOutDate( ( true == isset( $row["move_out_date"] ) ) ? $row["move_out_date"] : 'NULL' );
			$objWards->setReservationId( ( true == isset( $row["reservation_id"] ) ) ? $row["reservation_id"] : 'NULL' );
			$objWards->setReportingDoctorId( ( true == isset( $row["reporting_doctor_id"] ) ) ? $row["reporting_doctor_id"] : 'NULL' );
			$objWards->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objWards->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objWards->setFacilities( ( true == isset( $row["facilities"] ) ) ? $row["facilities"] : 'NULL' );
			$objWards->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objWards->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objWards->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objWards->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjWards, $objWards);
		}
		return $arrobjWards;
	}
	public function fetchAllWardsByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM WARDS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjWards = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWards->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWards->setRoomNumber( ( true == isset( $row["room_number"] ) ) ? $row["room_number"] : 'NULL' );
			$objWards->setWardTypeId( ( true == isset( $row["ward_type_id"] ) ) ? $row["ward_type_id"] : 'NULL' );
			$objWards->setRate( ( true == isset( $row["rate"] ) ) ? $row["rate"] : 'NULL' );
			$objWards->setIsAvaliable( ( true == isset( $row["is_avaliable"] ) ) ? $row["is_avaliable"] : 'NULL' );
			$objWards->setMoveOutDate( ( true == isset( $row["move_out_date"] ) ) ? $row["move_out_date"] : 'NULL' );
			$objWards->setReservationId( ( true == isset( $row["reservation_id"] ) ) ? $row["reservation_id"] : 'NULL' );
			$objWards->setReportingDoctorId( ( true == isset( $row["reporting_doctor_id"] ) ) ? $row["reporting_doctor_id"] : 'NULL' );
			$objWards->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objWards->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objWards->setFacilities( ( true == isset( $row["facilities"] ) ) ? $row["facilities"] : 'NULL' );
			$objWards->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objWards->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objWards->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objWards->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjWards, $objWards );
		}
		return $arrobjWards;
	}

	public function fetchWardsById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM WARDS WHERE id = " . $intId );
			$objWards = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWards = new BaseWards();
			$objWards->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWards->setRoomNumber( ( true == isset( $row["room_number"] ) ) ? $row["room_number"] : 'NULL' );
			$objWards->setWardTypeId( ( true == isset( $row["ward_type_id"] ) ) ? $row["ward_type_id"] : 'NULL' );
			$objWards->setRate( ( true == isset( $row["rate"] ) ) ? $row["rate"] : 'NULL' );
			$objWards->setIsAvaliable( ( true == isset( $row["is_avaliable"] ) ) ? $row["is_avaliable"] : 'NULL' );
			$objWards->setMoveOutDate( ( true == isset( $row["move_out_date"] ) ) ? $row["move_out_date"] : 'NULL' );
			$objWards->setReservationId( ( true == isset( $row["reservation_id"] ) ) ? $row["reservation_id"] : 'NULL' );
			$objWards->setReportingDoctorId( ( true == isset( $row["reporting_doctor_id"] ) ) ? $row["reporting_doctor_id"] : 'NULL' );
			$objWards->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objWards->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objWards->setFacilities( ( true == isset( $row["facilities"] ) ) ? $row["facilities"] : 'NULL' );
			$objWards->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objWards->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objWards->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objWards->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
		}
		return $objWards;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from wards order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endWards(){
		$this->connection->CloseMysql();
	}

}